<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<base href="<%=basePath%>">
<title>超市后台</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/bootstrap.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/main.css">
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/main.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.4.5/angular.min.js"></script>

<style>
.box_content {
	height: 100px;
	padding-left: 30px
}

.pageChange {
	float: right;
	color: #337ab7;
}

.pageChange>span {
	cursor: pointer
}

.pageChange>span:hover {
	color: blue
}

img {
	width: 60px;
	height: 50px
}
</style>

</head>
<body>
	<%@ include file="header.jsp"%>
	<%@ include file="left.jsp"%>
	<div id="index"
		style="position: absolute;left: 180px;top: 80px;bottom: 0;right: 0">
		<section id="main">
			<div class="scrollbar1-1" id="style1-1">
				<div class="main_div">
					<div class="main_title">
						<span>总部仓库</span>
					</div>
					<div class="blank"></div>
					<form class="form-inline" id="detailForm"
						style="margin-top: 30px;margin-left: 20px">
						<input style="display:none" value="7" id="pageCount"
							name="pageCount" />
						<div class="form-group">
							<label>商品分类:</label> <select id="selectType1"
								class="form-control"
								onclick="change1(this.value,'#selectType2');">
							</select>
						</div>
						<div class="form-group">
							<select id="selectType2" class="form-control" name="goodsType">
							</select>
						</div>
						<div class="form-group">
							<label for="orderCode"> 商品名称:</label> <input type="text"
								name="productName" class="form-control" id="productName"
								placeholder="">
						</div>
						<div class="form-group">
							<label for="ProductName"> 商品条码:</label> <input type="text"
								name="barCode" class="form-control" id="barCode" placeholder="">
						</div>
						<button onclick="selectinfo()" type="button"
							class="btn btn-primary">查询</button>
					</form>
				</div>
				<div class="force-overflow1-1">
					<table class="table table-condensed table-bordered table-hover"
						id="showtable" style="text-align: center">
						<tr style="background-color: #59c7d2">
							<th style="text-align: center">序号</th>
							<th style="text-align: center">略缩图</th>
							<th style="text-align: center">商品名称</th>
							<th style="text-align: center">商品条码</th>
							<th style="text-align: center">商品价格</th>
							<th style="text-align: center">操作</th>
						</tr>
					</table>
					<div class="pageChange">
						<span onclick="prePage()">&nbsp;&nbsp;上一页&nbsp;&nbsp;</span> <span
							onclick="nextPage()">&nbsp;&nbsp;下一页&nbsp;&nbsp;</span> <em>
							&nbsp; 第&nbsp;<span id="pageNum">1</span>&nbsp;页&nbsp;&nbsp;
						</em> <em>/&nbsp;&nbsp;共&nbsp;<span id="totalpage"></span>&nbsp;页
						</em> <em>&nbsp;&nbsp;&nbsp;跳到第<input id="searchInput"
							style="width:46px" maxlength="4" type="text">页
						</em>
						<button class="btn btn-primary" onclick="searchPage()">搜索</button>
					</div>
				</div>
			</div>
		</section>
	</div>
	<div class="bgBox" style="visibility:hidden">
		<div id="box">
			<div class="box_header textYellow">
				<span>详细资料</span>
			</div>
			<div class="scrollbar1-2" id="style1-1">
				<div class="form-horizontal">
					<div class="form-group">
						<label class="col-sm-3 control-label">商品名称</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" id="productNames"
								placeholder="请输入商品名称" disabled />
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">商品价格</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" placeholder="请输入商品价格"
								id="price" />
						</div>
					</div>

					<div class="form-group">
						<label class="col-sm-3 control-label">促销价</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" placeholder="请输入商品促销价"
								id="salePrice">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">会员价</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" placeholder="请输入商品会员价"
								id="vipPrice" />
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">商品数量</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" id="productCount"
								placeholder="请输入商品数量"> <input style="display:none"
								id="productID" />
						</div>
					</div>
					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-10">
							<div class="checkbox">
								<label> <input type="checkbox" id="commend">
									是否推荐
								</label>
							</div>
						</div>
					</div>

				</div>
				<div class="force-overflow1-2"></div>
			</div>
			<div class="box_footer">
				<ul>
					<li id="sureDetail" onclick="motaiHidden()">关闭</li>
					<li onclick="submitProduct(this)">提交</li>
				</ul>
			</div>
		</div>
	</div>
	<script type="text/javascript">	
		$(function() {
			selectinfo()
		})
	
		function selectinfo() {
			var barCode = $("#barCode").val();
			var pageNum = $("#pageNum").html();
			var pageCount = $("#pageCount").val();
			var productName = $("#productName").val();
			var selectType2 = $("#selectType2").find("option:selected").val()
			if (productName == "") {
				productName = null;
			}
			if (barCode == "") {
				barCode = null;
			}
			if (!selectType2) {
				selectType2 = null
			}
			$.post(urls + "productaAction/showProduct",
				{
					superId : localStorage.getItem("id"),
					goodsType : selectType2,
					barCode : barCode,
					pageNum : pageNum,
					pageCount : pageCount,
					productName : productName,
					checka:1
				},
				function(data) {
					console.log(data)
					if (data) {
						var totalpage = data.totalpage;
						var orderlist = data.headlist;
						var table = $("#showtable");
						$("tr").remove(".addtr");
						for (var i = 0; i < orderlist.length; i++) {
							var inactive1;
							if (orderlist[i].inactive1 == 1) {
								inactive1 = "已上架"
							} else {
								inactive1 = "<input onclick='detailinfo(\"" + 
								orderlist[i].productSimg +"|$" + 
								orderlist[i].productName +"|$" + 
								orderlist[i].barCode +"|$" + 
								orderlist[i].referenceValue +"|$" + 
								orderlist[i].productDetail +"|$" +
								orderlist[i].id +"|$" + 
								orderlist[i].productBimg +
								 "\")' type='button' class='btn btn-primary' value='上架' />"
							}
							var append = "<tr class='addtr'><td>" + (i + 1) + "</td>" +
								"<td ><img src='/goods/" + orderlist[i].productSimg + "' alt='加载中'/> </td>" +
								"<td>" + orderlist[i].productName + "</td>" +
								"<td>" + orderlist[i].barCode + "</td>" +
								"<td>" + orderlist[i].referenceValue + "</td>" +
								"<td>" + inactive1 + "</td></tr>";
							table.append(append);
						}
						$("#totalpage").html(totalpage);
					}
				}
				, "json"
			)
		}
		function detailinfo(e) {
			var attr = e.split("|$");
			$(".bgBox").css("visibility", "visible");
			$("#productNames").val(attr[1]);
			$("#price").val(attr[3]);
			$("#productID").val(attr[5]);
		}
		function submitProduct() {
			var recommends = 0;
			if ($("#commend").is(':checked')) {
				recommends = 1;
			}
			if ($(productCount).val()) {
				$.post(urls + "productaAction/putaway",
					{
						recommend : recommends,
						productName : $("#productNames").val(),
						referenceValue : $("#price").val(),
						promotionPrice : $("#vipPrice").val(),
						discountPrice : $("#salePrice").val(),
						headID : $("#productID").val(),
						repertory : $("#productCount").val(),
						superId : localStorage.getItem("id"),
						putaway : 1
					}, function(res) {
						if (res == false) {
							alert("提交失败")
						} else {
							alert("提交成功");
							selectinfo()
						}
					})
			} else {
				alert("请填写完整商品信息");
			}
			$(".bgBox").css("visibility", "hidden");
		}
		function motaiHidden() {
			$(".bgBox").css("visibility", "hidden");
		}
	</script>
</body>
</html>